package com.qianda.qdminiapp.service;

import com.qianda.qdminiapp.SpringBeansLocator;
import com.qianda.qdminiapp.common.constant.CommonConstant;
import com.qianda.qdminiapp.common.exception.ExceptionCode;
import com.qianda.qdminiapp.common.exception.SimpleException;

/**
 * 支付选择器
 * @ClassName PaymentSelector
 * @Author cw
 * @Date 2019/8/7 15:13
 * @Version 1.0
 */
public class PaymentSelector {

    /**
     * 根据支付方式获取支付
     * @param payWay  支付方式
     * @return  PaymentStrategy
     */
    public static OrderAndPaymentStrategy getPaymentSelector(Integer payWay) {
        OrderAndPaymentStrategy orderAndPaymentStrategy = null;

        if (CommonConstant.PayType.PAY_TYPE_WX == payWay) {// 微信支付
            orderAndPaymentStrategy = SpringBeansLocator.getBean(OrderAndPaymentStrategy.class, "wxPaymentImpl");
        } else if (CommonConstant.PayType.PAY_TYPE_BALANCE == payWay) {// 余额
            orderAndPaymentStrategy = SpringBeansLocator.getBean(OrderAndPaymentStrategy.class, "balancePaymentImpl");
        } else if (CommonConstant.PayType.PAY_TYPE_QQD == payWay) {// 千豆支付
            orderAndPaymentStrategy = SpringBeansLocator.getBean(OrderAndPaymentStrategy.class, "qqdPaymentImpl");
        } else {
            throw new SimpleException(ExceptionCode.EX_PAY_WAY_ERR);
        }
        return orderAndPaymentStrategy;
    }
}
